package com.example.admin.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.admin.R;
import com.example.admin.SQLite.LunTan;
import com.example.admin.SQLite.ScBean;
import com.example.admin.SQLite.SqLiteOpenHelper;
import com.example.admin.SQLite.User;
import com.example.admin.SQLite.dao.LunTanDao;
import com.example.admin.SQLite.dao.ScBeanDao;
import com.example.admin.adapter.ForumLunTanAdapter;
import com.example.admin.base.BaseActivity;
import com.orhanobut.hawk.Hawk;

import java.util.ArrayList;

//我的论坛
public class ForumMineActivityAd extends BaseActivity {

    ScBeanDao scBeanDao;
    LunTanDao lunTanDao;
    SqLiteOpenHelper dbHelper;
    ForumLunTanAdapter mAdapter;
    RecyclerView recyclerView;

    @Override
    public void setContentView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_forum_minead);
        scBeanDao = new ScBeanDao(this);
        lunTanDao = new LunTanDao(this);
        mAdapter = new ForumLunTanAdapter();
        mAdapter.setBoo(false);
        recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                startActivity(new Intent(ForumMineActivityAd.this, ForumDetailsActivity.class)
                        .putExtra("bean", mAdapter.getItem(position)));
            }
        });
        mAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                AlertDialog.Builder builder = new AlertDialog.Builder(ForumMineActivityAd.this);
                builder.setTitle("是否执行此操作");
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        dbHelper.DeleteContacts(mAdapter.getItem(position).id);
                        mAdapter.remove(position);
                    }
                });
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
                AlertDialog dialog = builder.create();
                dialog.show();
            }
        });

    }

    @Override
    public void setInitView() {

    }

    @Override
    public void onStart() {
        super.onStart();
        getdata1();
    }


    private void getdata1() {
        ArrayList<LunTan> lists = new ArrayList<>();
        ArrayList<LunTan> list = lunTanDao.getComPlans();
        ArrayList<ScBean> data = scBeanDao.FindWhereSC1( "-1");
        for (LunTan bean : list) {
            for (ScBean be : data) {
                if (be.ids == bean.id) {
                    lists.add(bean);
                }
            }

        }

        mAdapter.setNewData(lists);
    }

}